import request from "@/router/axios"
import Mock from "mockjs";

const list = Mock.mock({
    "tableList|50-100": [{
        "user_id|111111-999999": 100,
        shop_name: "iphone13",
        "shop_price|1111-9999": 100,
        shop_type: "手机",
        "shop_num|8-30": 100,
        create_time: "@datetime",
        "status|1": ["已发货", "未发货"],
        "user_type|1": ["会员用户", "普通用户"]
    }]
})
console.log(list)

Mock.mock(/\/list/, config => {
    return {
        data: {
            list: list.tableList,
            code: 200,
        }
    }
})


export const orderListMock = () => request({
        url: "/list",
        method: "get"
    })
    // 造一个接口 
    /*
        pagenum 当前第几页 必填  Number
        pagesize 一页显示多少条 必填 Number
        age 根据年龄进行模糊查询数据 不必填 Number
        接口的名： /orderMyList 
        请求方式 ：post,
        
        数据模拟：data:{
            pagenum:1,
            pagesize:10,
            age :1 
        }
    */
export const orderMyList = (data) => request({
    url: "/orderMyList",
    method: "post",
    data
})
Mock.mock(/\/orderMyList/, config => {
    console.log(JSON.parse(config.body))
    let { pagenum, pagesize, age } = JSON.parse(config.body);
    // 获取到list的数据里面tableList
    let _list = list.tableList;
    // 总条数
    let total = _list.length;
    if (age) {
        _list = _list.filter((item, index) => {
            if (item.age.toString().indexOf(age) == -1) {
                return false
            } else {
                return true
            }
        })
    }
    // 根据当前第几页 和一页显示几条 返回相应数据
    // user返回的数据
    let user = _list.filter((item, index) => index < pagesize * pagenum && index >= pagesize * (pagenum - 1));
    // 返回数据
    return {
        data: {
            user,
            total
        }
    }
})